define(function (require, exports, module) {
    var $ = require("jquery");
    var angular = require("angular");
    var ui = require('ui');
    var util = require('util');
    require("angular-ui");

    var api_prefix = G_CONFIG["api_prefix"] + "/qmyx/para-setting/"; //api前缀
    angular.module('PublicRuleAgreement', [])
        .service("RuleAgreementSettingService", ['$http', function ($http) {
            return {getService:function(){
                return $http.get(api_prefix + 'get-rule-protocol-add');
            }}
        }])
        .controller('RuleAgreementController', ['$scope', '$http', 'RuleAgreementSettingService', function ($scope, $http, RuleAgreementSettingService) {
            $scope.isFormValid = false;
            $scope.save = function (formValid) {
                var data = $scope.data;
                if (!formValid) {
                    return;
                }
                $http.post(
                    api_prefix + "save-rule-protocol-add",
                    {
                        token: util.getToken(),
                        activityUrl: data.activityUrl,
                        agencyAgreementTitle: data.agencyagreementtitle,
                        agencyAgreementUrl: data.agencyagreementurl,
                        agreementTitle: data.agreementtitle,
                        agreementUrl: data.agreementurl,
                        seekingAttentionUrl: data.seekingAttentionUrl,
                        msgTempLateId: data.MsgTemplateID
                    }
                )
                    .success(function (res) {
                        ui.showSucTip();
                    })
            };



            RuleAgreementSettingService.getService().then(function (res) {
                var retCode = res.data.retCode;
                if (retCode == 0) {

                } else {
                    ui.showErrTip(res.data.errMsg);
                    return false;
                }
                $scope.data = res.data.data;
            })
        }])
});